<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户订阅记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>用户标识：</label>
                                <input type="text" name="userIdentify"/>
                            </li>
                            <li>
                                <label>设备标识：</label>
                                <input type="text" name="deviceIdentify"/>
                            </li>
                            <li>
                                <label>应用：</label>
                                <select id ="productId" name="productId" onchange="selectGoodType()">
                                    <option value="">请选择应用</option>
                                    <option th:each="product:${productList}" th:text="${product.name}" th:value="${product.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>服务：</label>
                                <select id="goodsTypeId" name="goodsTypeId">
                                    <option value="">请选择服务</option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select id="status" name="status">
                                    <option value="">请选择状态</option>
                                    <option value="0">失效</option>
                                    <option value="1">有效</option>
                                </select>
                            </li>
                            <li>
                                有效开始时间：
                                <input type="text" class="time-input" placeholder="请选择有效开始时间" name="effictStartTime"/>
                            </li>
                            <li>
                                有效截止时间：
                                <input type="text" class="time-input" placeholder="请选择有效截止时间" name="effictEndTime"/>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;查询</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="product:userSubRecord:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="product:userSubRecord:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
               <!-- <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="product:userSubRecord:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="product:userSubRecord:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('product:userSubRecord:edit')}]];
        var removeFlag = [[${@permission.hasPermi('product:userSubRecord:remove')}]];
        var prefix = ctx + "product/userSubRecord";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/form",
                updateUrl: prefix + "/form/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "用户订阅记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '${comment}',
                    visible: false
                },
                {
                    field: 'userIdentify',
                    title: '用户标识'
                },
                {
                    field: 'deviceIdentify',
                    title: '设备标识'
                },
                {
                    field: 'productName',
                    title: '应用名称'
                },
                {
                    field: 'goodsTypeName',
                    title: '服务名称'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if(value == 1){
                            return "有效";
                        }else if(value == 0){
                            return "失效";
                        }
                        return "";
                    }
                },
                {
                    field: 'effictStartTime',
                    title: '有效开始时间'
                },
                {
                    field: 'effictEndTime',
                    title: '有效截止时间'
                },
                {
                    field: 'effictTransferTime',
                    title: '转写时间（秒）'
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function selectGoodType() {
            var productId = $("#productId").val();
            $.ajax({
                type: "GET",
                url: ctx + "product/goods/addChangeProduct?productId="+productId,
                cache: false,
                dataType: 'json',
                success: function(result) {
                    if (result) {
                        var html = "<option value=''>请选择服务</option>";
                        for (var i = 0; i < result.length; i++) {
                            html += "<option value='" + result[i].id + "'>" + result[i].name + "</option>"
                        }
                        $('#goodsTypeId').html(html);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("失败。");
                }
            });
        }
    </script>
</body>
</html>